package com.pb.b2b.faces.components;

import java.io.IOException;

import javax.faces.component.FacesComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;

import com.pb.b2b.util.FacesUtils;

@FacesComponent("pb.SaveBean")
public class SaveBean extends UIComponentBase {
	private Object bean;
	private String beanName;

	@Override
	public String getFamily() {
		return "pb.SaveBean";
	}

	@Override
	public void encodeBegin(FacesContext context) throws IOException {
		super.encodeBegin(context);
		beanName = (String) getAttributes().get("beanName");
		bean = FacesUtils.getFlash().get(beanName);
		if (bean != null) {
			FacesUtils.setViewMap(beanName, bean);

		}
	}

	@Override
	public void decode(FacesContext context) {
		bean = getAttributes().get("bean");
		if (bean != null) {
			beanName = (String) getAttributes().get("beanName");
			FacesUtils.getFlash().put(beanName, bean);
		}

	}

}
